package ru.urfc.portal.ui.client.googlets.client;

import ru.urfc.portal.ui.client.BaseGooglet;
import ru.urfc.portal.ui.client.descriptor.CompositeGridField;
import ru.urfc.portal.ui.client.descriptor.GridDescriptor;
import ru.urfc.portal.ui.client.model.catalogs.UserState;
import ru.urfc.portal.ui.client.renderers.UserNameRenderer;
import ru.urfc.portal.ui.client.widgets.MegaGrid;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.AnchorElement;
import com.google.gwt.dom.client.Element;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Widget;

public class AssociatedUserList extends BaseGooglet {

	interface Binder extends UiBinder<Widget, AssociatedUserList> {}
	private static Binder binder = GWT.create(Binder.class);

	@UiField MegaGrid grid;
	@UiField Element title;
	@UiField AnchorElement createUser;
	
	@Override
	protected void init() {
		initWidget(binder.createAndBindUi(this));
		title.setInnerText("Пользователи");
		createUser.setHref(patchHref(PAGE_ASSOCIATED_USER_CREATE));

		GridDescriptor descriptor = new GridDescriptor(USER, CLIENTS, getClientId(), CLIENT_ASSOCIATED_USERS);
		CompositeGridField fioField = 
			descriptor.addCompositeField("firstName", "middleName", "lastName", "email");
		descriptor.assign(new UserNameRenderer(fioField, null));
		descriptor.addAnchorColumn(fioField, "id", PAGE_ASSOCIATED_USER_EDIT, "e-mail", 200);
		descriptor.addTextColumn("role/text", "Роль", 150);
		descriptor.addCIColumn("state/text", "state/code", UserState.class, "Статус разрешения", 100);
		
		createController(descriptor, grid);
        grid.setAutoExpandColumn(fioField.getName());
	}

}